﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Enterprise.Service.Caiwubu
{
    /// <summary>
    /// 未建表进行存储
    /// 如果未来增加或减少指标，请维护zbmc变量和dwmc，或建库进行存储（一张表两个字段即可）
    /// </summary>
    public class KHBService
    {
        /// <summary>
        /// 领导关心的指标名称
        /// </summary>
        public string[] zbmc = { 
                                   "净利润", 
                                   "运营净现金流", 
                                   "权益油气产量", 
                                   "新增权益油气可采储量",
                                   "原油商品率",
                                   "单位现金操作成本",
                                   "管理费用",
                                   "单位销售费用",
                                    "员工总数",
                                    "实物工作量完成率",
                                    "投资完成率"
                               };
        /// <summary>
        /// 分公司名称
        /// </summary>
        public string[] dwmc = { "SZK", "PPC","SPC"};


        /// <summary>
        /// 生成空表
        /// </summary>
        /// <param name="nf"></param>
        /// <param name="yf"></param>
        public void Add(string nf,string yf)
        {
            Data.Common.Data cmd = new Data.Common.Data();
            if (!cmd.Exist("select count(1) from cwb_khb where nf=" + nf + " and yf=" + yf + ""))
            {
                string sql = "begin ";
                string insertsql = "Insert into cwb_khb(NF,YF,ZBMC,DWMC) values ({0},{1},'{2}','{3}');";
                foreach (string dw in dwmc)
                {
                    foreach (string zb in zbmc)
                    {
                        sql += string.Format(insertsql, nf, yf, zb,dw);
                    }
                }
                sql += "null;end;";
                cmd.ExcuteSql(sql);
            }
        }

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="sql"></param>
        public void Update(string sql)
        {
            Data.Common.Data cmd = new Data.Common.Data();
            cmd.ExcuteSql(sql);
        }

        /// <summary>
        /// 获取数据
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public System.Data.DataSet GetDataSet(string sql)
        {
            Enterprise.Data.Common.Data data = new Data.Common.Data();
            return data.GetDataSet(sql);
        }
        
    }
}
